/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Listeners;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import shutdown.SwingIO;

/**
 *
 * @author Joel
 */
public class MainMenuListener implements ActionListener {

    private static final String EXIT = "exit";
    private static final String HELP = "basics";
    private static final String START_LOG = "start logging";
    private static final String ABOUT = "about...";

    private static final MainMenuListener mml = new MainMenuListener();

    private MainMenuListener() {};

    public static MainMenuListener getInstance() {
        return mml;
        }

    @Override
    public void actionPerformed(ActionEvent e) {
        String action = e.getActionCommand();
        if (action.equalsIgnoreCase(EXIT)) {
            System.err.println("End\n");
            System.exit(0);
            }
        if (action.equalsIgnoreCase(HELP)) {
            Scanner help = null;
            try {
                help = new Scanner(new File("help.txt"));
            } catch (FileNotFoundException ex) {
                System.err.println(ex.getLocalizedMessage());
                ex.printStackTrace();
                return;
                }
            StringBuilder stb = new StringBuilder();
            while (help.hasNextLine())
                stb.append(help.nextLine() + "\n");
            SwingIO.infoMsg(stb.toString(), "Help");
            stb = null;
            }
        if (action.equalsIgnoreCase(START_LOG)) {
            //MenuItem item = (MenuItem) e.getSource();
            //TrayIcon trayIcon = (TrayIcon)((Menu)(item.getParent())).getParent();
            SwingIO.infoMsg("To be implemented", "Already Logging");
            }
        if (action.equalsIgnoreCase(ABOUT))
            SwingIO.infoMsg("Auto Shutdown Ver 1.7\nBy Joel Jauregui", "About");
        }
    }
